package com.ugoodtech.mdcc.web.controller;

import com.ugoodtech.mdcc.core.repository.DepartmentRepository;
import com.ugoodtech.mdcc.core.repository.UserProfileRepository;
import com.ugoodtech.mdcc.core.repository.UserRepository;
import com.ugoodtech.mdcc.web.service.StationTechColorReportService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Copyright © 2013 All Rights Reserved, Ugood Technology, Inc.
 */

@Api(description = "颜色能力分析报告")
@Controller
@RequestMapping("/stationTechColorReport")
public class StationTechColorReportController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(StationTechColorReportController.class);
    @Autowired
    UserRepository systemUserRepository;
    @Autowired
    UserProfileRepository userProfileRepository;
    @Autowired
    StationTechColorReportService stationTechColorReportService;
    @Autowired
    DepartmentRepository departmentRepository;

    @Autowired
    private PasswordEncoder passwordEncoder;


//    @ApiOperation("颜色能力分析报告列表")
//    @ApiResponses({
//            @ApiResponse(code = 200, message = "data", response = User.class)
//    })
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int"),
//            @ApiImplicitParam(name = "size", value = "每页条数", required = false, paramType = "query", dataType = "int"),
//    })
//    @RequestMapping(value = "/list", method = RequestMethod.GET)
//    @ResponseBody
//    public JsonResponse getAllDepartment(@ApiParam("省份") @RequestParam(value = "province", required = false) String province,
//                                         @ApiParam("城市") @RequestParam(value = "city", required = false) String city,
//                                         @ApiParam("维修站类型") @RequestParam(value = "category", required = false)StationCategory category,
//                                         @ApiParam("品牌") @RequestParam(value = "brand", required = false)AutoBrand brand,
//                                         @ApiParam("关键字") @RequestParam(value = "param", required = false) String param,
//                                         @ApiParam("外勤人员关键字") @RequestParam(value = "userParam", required = false) String userParam,
//                                         Pageable pageable) {
//        isUserLogin();
//        Page<StationTechColorReport> stationTechColorReport = stationTechColorReportService.queryReport(province,city,category,brand,param,userParam,pageable);
////        for(Department department:departments){
////            setChildren(department);
////        }
//        Page<StationTechColorReportResponse> stationTechColorReportResponses=BaseUtil.getDtoPage(stationTechColorReport,pageable, StationTechColorReportResponse.class);
//        for(StationTechColorReportResponse stationTechColorReportResponse:stationTechColorReportResponses){
//            UserProfile userProfile=userProfileRepository.findByUserId(stationTechColorReportResponse.getUserId());
//            if(null!=userProfile){
//                stationTechColorReportResponse.setUserName(userProfile.getRealName());
//            }
//        }
//        return JsonResponse.successResponseWithPageData(stationTechColorReportResponses);
//    }



//    @ApiOperation("编辑")
//    @RequestMapping(value = "/edit", method = RequestMethod.POST)
//    public JsonResponse edit(
//            StationTechColorReport stationTechColorReport,
//            HttpServletRequest httpServletRequest
//    ) {
//        isUserLogin();
//        StationTechColorReport  savedStationTechColorReport=stationTechColorReportRepository.findOne(stationTechColorReport.getId());
//        Map params=getParams(httpServletRequest);
//        copyExistField(savedStationTechColorReport,params);
//        stationTechColorReportRepository.save(savedStationTechColorReport);
//        return JsonResponse.successResponse();
//    }
//
//    public Map<String,String> getParams(HttpServletRequest httpServletRequest){
//        Map paramMap = new HashMap();
//        Enumeration paramNames = httpServletRequest.getParameterNames();
//        while (paramNames.hasMoreElements()) {
//            String paramName = (String) paramNames.nextElement();
//            String[] paramValues = httpServletRequest.getParameterValues(paramName);
//            if (paramValues.length == 1) {
//                String paramValue = paramValues[0];
//                if (paramValue.length() != 0) {
//                    paramMap.put(paramName, paramValue);
//                }
//            }
//        }
//        return paramMap;
//    }

//    public void copyExistField(StationTechColorReport stationTechColorReport,Map<String,String> datas){
//        Class cls = stationTechColorReport.getClass();
//        for(String key : datas.keySet()){
//            try {
//                Field f=cls.getField(key);
//                f.set(stationTechColorReport,datas.get(key));
//                System.out.println("修改属性:" + f.getName() + " 属性值修改为:" + f.get(stationTechColorReport));
//            } catch (NoSuchFieldException e) {
//                System.out.println("没有字段:" + key);
//                e.printStackTrace();
//            } catch (SecurityException e) {
//                e.printStackTrace();
//            } catch (IllegalAccessException e) {
//                e.printStackTrace();
//            }
//        }
////        Field[] fields = cls.getDeclaredFields();
////        for(int i=0; i<fields.length; i++){
////            Field f = fields[i];
////            f.setAccessible(true);
////            System.out.println("属性名:" + f.getName() + " 属性值:" + f.get(stationTechColorReport));
////        }
//    }


//    @ApiOperation("审核报告")
//    @RequestMapping(value = "/confirmReport", method = RequestMethod.POST)
//    public JsonResponse confirmReport(@ApiParam(value = "用户数据库id", required = true) @RequestParam(value = "stationTechColorReportId") Long stationTechColorReportId,
//                                      @ApiParam(value = "通过/不通过", required = true) @RequestParam(value = "confirm") boolean confirm) {
//        isUserLogin();
//        StationTechColorReport stationTechColorReport = stationTechColorReportRepository.findOne(stationTechColorReportId);
//        if(confirm){
//            stationTechColorReport.setStatus(StationTechColorReport.TechColorReportStatus.publish);
//        }else{
//            stationTechColorReport.setStatus(StationTechColorReport.TechColorReportStatus.audit_reject);
//        }
//
//        stationTechColorReportRepository.save(stationTechColorReport);
//        return JsonResponse.successResponse();
//    }


}
